import { createSlice,createAsyncThunk } from "@reduxjs/toolkit";
import { getBanners } from "../service/recommend";


export const fetchBannerDataAction = createAsyncThunk("banners",async (arg,{dispatch}) => {
    const res = await getBanners()
    console.log(res)
    dispatch(changeBannersAction(res.banners))
})


export interface IBanners{
    bannerBizType:string,
    encodeId:string
    exclusive:boolean
    imageUrl:string
    scm: string
    targetId:number
    targetType: number
    titleColor:string
    typeTitle:string
}

interface IRecommendStateState  {
    banners:IBanners[]
}

const initialState :IRecommendStateState= {
    banners:[]
}

const recommendSlice = createSlice({
    name: "recommend",
    initialState,
    reducers:{
        changeBannersAction(state, { payload }) {
            state.banners=payload
        }
    }
    
})
export const {changeBannersAction} =recommendSlice.actions
export default recommendSlice.reducer